﻿--[[
    @brief      Lua模拟Stack结构
    @author     jameszhai
    @version    1.0
    @date       2016-04-26
]]

Stack = 
{
};

function Stack:new()
    local   pObjt = {};

    setmetatable(pObjt, self);
    self.__index = self;

    return pObjt;
end;

function Stack:Push(cValue)
    table.insert(self, cValue);
    return  self:Size();
end;

function Stack:Pop()
    local nSize = self:Size();

    if 0 == nSize then
        return  nil;
    else
        return table.remove(self, nSize);
    end;
end;

function Stack:Top()
    local   nSize = self:Size();

    if 0 == nSize then
        return  nil;
    else
        return  self[nSize];
    end;
end;

function Stack:IsEmpty()
    local nSize = self:Size();

    if 0 == nSize then
        return true;
    end;

    return false;
end;

function Stack:Size()
    return  table.getn(self);
end;

function Stack:Clear()
    self = {};
end;